package com.kaifamiao.strings;

import java.nio.charset.StandardCharsets;

// 关注 String 类的部分构造方法
public class StringConstructor {

    public static void main(String[] args) {

        // 在堆中构造一个空字符串
        String s = new String();
        System.out.println( s.length() );

        // String(String s)
        String t = new String( "开发喵" );
        System.out.println( t );

        byte[] bytes = { -27, -68, -128, -27, -113, -111, -27, -106, -75 };
        // String(byte[] arr, Charset cs)
        String p = new String( bytes, StandardCharsets.UTF_8 );
        System.out.println( p );

        // String(byte[] arr, int offset, int length, Charset cs)
        p = new String(bytes, 0, 6 , StandardCharsets.UTF_8);
        System.out.println( p );

        char[] chars = { '倭', '寇', '不', '灭', '何', '以', '为', '家' };
        // String(char[] arr)
        String x = new String( chars );
        System.out.println( x );

        // String(char[] arr, int offset, int count)
        x = new String(chars, 0, 4 );
        System.out.println( x );

    }

}
